package ServerConnection;

import Client.AddFriendActionListener;
import ServerConnection.DatabaseServer;
import ServerConnection.GetFriendArrayListServer;
import ServerConnection.AccountSignUpServer;

/*
 * Server类负责多线程创建多个ServerSocket
 * 然后在run()中通过不同的ServerSocket创建不同的socket线程循环监听来自不同端口的消息
 * */
public class Server {
    DatabaseServer databaseServer;
    GetFriendArrayListServer getFriendArrayListServer;
    AccountLoginServer accountLoginServer;
    AccountSignUpServer accountSignUpServer;
    AccountAddFriendServer accountAddFriendServer;
    ReturnAccountSendMessageInfoServer returnAccountSendMessageInfoServer;
    AccountSendMessageInfoServer accountSendMessageInfoServer;

    public Server() {
        databaseServer = new DatabaseServer();
        getFriendArrayListServer = new GetFriendArrayListServer(databaseServer);
        accountLoginServer = new AccountLoginServer(databaseServer);
        accountSignUpServer = new AccountSignUpServer(databaseServer);
        accountAddFriendServer = new AccountAddFriendServer(databaseServer);
        returnAccountSendMessageInfoServer = new ReturnAccountSendMessageInfoServer(databaseServer);
        accountSendMessageInfoServer = new AccountSendMessageInfoServer(databaseServer);

    }

    public static void main(String[] args) {
        Server server = new Server();
        server.start();
    }

    public void start() {
        Thread t1 = new Thread(getFriendArrayListServer);
        Thread t2 = new Thread(accountLoginServer);
        Thread t3 = new Thread(accountSignUpServer);
        Thread t4 = new Thread(accountAddFriendServer);
        Thread t5 = new Thread(returnAccountSendMessageInfoServer);
        Thread t6 = new Thread(accountSendMessageInfoServer);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
    }
}